﻿using Jiguang.JPush.Model;
using Microsoft.Extensions.DependencyInjection;

namespace PmSoft.Jiguang
{
    /// <summary>
    /// 激光推送
    /// </summary>
    [UseDI(ServiceLifetime.Scoped)]
    public class JiguangService : IJiguangService
    {
        private readonly JiguangRepository jiguangRepository;

        public JiguangService(JiguangRepository jiguangRepository)
        {
            this.jiguangRepository = jiguangRepository;
        }

        public async Task AppointPush(AppointPushModel push)
        {
            PushPayload payload = new PushPayload();
            payload.Platform = new List<string> { "android", "ios" }; // 推送平台，可根据需求设置
            payload.Audience = new Audience()
            {
                Alias = push.TargetAlias
            };
            payload.Notification = new Notification()
            {
                Alert = push.Message,
                Android = new Android
                {
                    Alert = push.Message,
                    Title = push.Title,
                    Extras = push.Extras
                }
            };

            await jiguangRepository.SendPush(payload);
        }

        public async Task BroadcastPush(BroadcastPushModel push)
        {
            PushPayload payload = new PushPayload();
            payload.Platform = new List<string> { "android", "ios" }; // 推送平台，可根据需求设置
            payload.Audience = "all"; // 推送目标，这里设置为所有用户
            payload.Notification = new Notification()
            {
                Alert = push.Message,
                Android = new Android
                {
                    Alert = push.Message,
                    Title = push.Title,
                    Extras = push.Extras
                }
            };
            await jiguangRepository.SendPush(payload);
        }
    }
}
